home *** CD-ROM | disk | FTP | other *** search
- /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- % Copyright (C) 1995, by WATCOM International Inc. All rights %
- % reserved. No part of this software may be reproduced or %
- % used in any form or by any means - graphic, electronic or %
- % mechanical, including photocopying, recording, taping or %
- % information storage and retrieval systems - except with the %
- % written permission of WATCOM International Inc. %
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- */
-
- /*************************************************************************
- *
- * WListView -- Wrapper for the Windows 95 ListView control.
- *
- * Note that currently columnNumber is equivalent to subItemNumber,
- * but the Windows 95 docs seem to imply otherwise so at some point
- * they may in fact refer to different things.
- *
- *
- * Events:
- *
- * BeginLabelEdit -- When direct editing of a label begins.
- *
- * BeginOwnerDraw -- Occurs before the 1 or more DrawItem events.
- *
- * Change -- Occurs whenever an item changes state (i.e., is
- * selected/deselected).
- *
- * Click -- When an item is clicked.
- *
- * ColumnClick -- When a column header is clicked.
- *
- * DataAvailable --
- *
- * DataClose --
- *
- * DataOpen --
- *
- * DataRequest --
- *
- * DoubleClick -- When an item is double-clicked.
- *
- * DrawItem -- When WLVSOwnerDraw style used and in report mode.
- *
- * EndLabelEdit -- When direct editing of a label ends.
- *
- * EndOwnerDraw -- Occurs after the DrawItem events.
- *
- * InsertItem -- Called immediately after an item is added.
- *
- * NeedItemText --
- *
- *************************************************************************/
-
- #ifndef _WLISTVW_HPP_INCLUDED
- #define _WLISTVW_HPP_INCLUDED
-
- #ifndef _WNO_PRAGMA_PUSH
- #pragma pack(push,8);
- #pragma enum int;
- #endif
-
- #ifndef _WCONTROL_HPP_INCLUDED
- # include "wcontrol.hpp"
- #endif
- #ifndef _WDRAWITM_HPP_INCLUDED
- # include "wdrawitm.hpp"
- #endif
- #ifndef _WIMGLIST_HPP_INCLUDED
- # include "wimglist.hpp"
- #endif
- #ifndef _WARRAY_HPP_INCLUDED
- # include "warray.hpp"
- #endif
- #ifndef _WDATATRG_HPP_INCLUDED
- # include "wdatatrg.hpp"
- #endif
-
- class WListView;
-
- enum WLVColumnFormat {
- WLVCLeft,
- WLVCCenter,
- WLVCRight,
- };
-
- #define WLVMaskText 0x0001
- #define WLVMaskImage 0x0002
- #define WLVMaskParam 0x0004
- #define WLVMaskState 0x0008
-
- struct WListViewEventData : public WEventData {
- WLong itemNumber;
- WLong subItemNumber;
- WULong newState;
- WULong oldState;
- WULong changedMask;
- WPoint dragPosition;
- const WChar * itemText;
- };
-
- struct WListViewDispEventData : public WEventData {
- WUInt mask;
- WInt itemNumber;
- WInt subItemNumber;
- WUInt state;
- WUInt stateMask;
- const WChar * itemText;
- WInt textMax;
- WInt imageIndex;
- void * userData;
- };
-
- typedef int WCMDEF (*WListViewSortCallback)( void * item1userData, void * item2userData, WListView * listView );
- typedef int WCMDEF (WObject::*WListViewSortMemberCallback)( void * item1userData, void * item2userData, WListView * listView );
-
- typedef WArray< WULong > WULongArray;
-
- //
- // ListView styles
- //
-
- #define WLVSDefault ((WStyle)0x50000100L) // WS_VISIBLE|LVS_ICON|LVS_ALIGNTOP|LVS_AUTOARRANGE|WS_CHILD
- #define WLVSAlignTop ((WStyle)0x00000000L) // LVS_ALIGNTOP
- #define WLVSIcon ((WStyle)0x00000000L) // LVS_ICON
- #define WLVSReport ((WStyle)0x00000001L) // LVS_REPORT
- #define WLVSSmallIcon ((WStyle)0x00000002L) // LVS_SMALLICON
- #define WLVSList ((WStyle)0x00000003L) // LVS_LIST
- #define WLVSSingleSelection ((WStyle)0x00000004L) // LVS_SINGLESEL
- #define WLVSShowSelAlways ((WStyle)0x00000008L) // LVS_SHOWSELALWAYS
- #define WLVSAlwaysShowSelection ((WStyle)0x00000008L) // LVS_SHOWSELALWAYS
- #define WLVSSortAscending ((WStyle)0x00000010L) // LVS_SORTASCENDING
- #define WLVSSortDescending ((WStyle)0x00000020L) // LVS_SORTDESCENDING
- #define WLVSShareImageLists ((WStyle)0x00000040L) // LVS_SHAREIMAGELISTS
- #define WLVSNoLabelWrap ((WStyle)0x00000080L) // LVS_NOLABELWRAP
- #define WLVSAutoArrange ((WStyle)0x00000100L) // LVS_AUTOARRANGE
- #define WLVSEditLabels ((WStyle)0x00000200L) // LVS_EDITLABELS
- #define WLVSOwnerDraw ((WStyle)0x00000400L) // LVS_OWNERDRAWFIXED
- #define WLVSAlignLeft ((WStyle)0x00000800L) // LVS_ALIGNLEFT
- #define WLVSNoScroll ((WStyle)0x00002000L) // LVS_NOSCROLL
- #define WLVSNoColumnHeaders ((WStyle)0x00004000L) // LVS_NOCOLUMNHEADER
- #define WLVSNoSortHeader ((WStyle)0x00008000L) // LVS_NOSORTHEADER
-
- #define WLVSOwnerDrawFixed WLVSOwnerDraw
- #define WLVSSingleSel WLVSSingleSelection
- #define WLVSAlwaysShowSel WLVSAlwaysShowSelection
- #define WLVSNoColumnHeader WLVSNoColumnHeaders
-
- enum WLVViewType {
- WLVTIcon,
- WLVTReport, WLVTDetail = WLVTReport,
- WLVTSmallIcon,
- WLVTList,
- };
-
- enum WLVRectType {
- WLVRText,
- WLVRIcon,
- WLVRSelectBounds,
- WLVRBounds
- };
-
- enum WLVAlignment {
- WLVADefault = 0,
- WLVALeft = 1,
- WLVATop = 2,
- WLVASnapToGrid = 5
- };
-
- enum WLVSort {
- WLVSNone = 0x0000,
- WLVSAscending = 0x0100,
- WLVSDescending = 0x0200,
- };
-
- enum WLVImageListType {
- WLVINormal, WLVILarge=WLVINormal,
- WLVISmall,
- WLVIState
- };
-
- enum WLVColumnAlignment {
- WLVCALeft,
- WLVCARight,
- WLVCACenter,
- };
-
- #define WLVNIAll 0x0000
- #define WLVNIFocused 0x0001
- #define WLVNISelected 0x0002
- #define WLVNICut 0x0004
- #define WLVNIDropHilited 0x0008
- #define WLVNIAbove 0x0100
- #define WLVNIBelow 0x0200
- #define WLVNIToLeft 0x0400
- #define WLVNIToRight 0x0800
-
- #define WLVFocusedState 0x0001
- #define WLVSelectedState 0x0002
- #define WLVCutState 0x0004
- #define WLVDropHilitedState 0x0008
-
- class WListView;
-
- typedef WBool WCMDEF (WObject::*WListViewCallback)( WListView * listView, WULong itemNumber, void * userData );
-
- class WCMCLASS WListView : public WControl {
- WDeclareSubclass( WListView, WControl );
-
- public:
-
- /**********************************************************
- * Constructors and Destructors
- *********************************************************/
-
- WListView();
-
- ~WListView();
-
- /**********************************************************
- * Properties
- *********************************************************/
-
- // ColumnCount
- //
- // Returns the number of columns in report mode.
-
- WInt GetColumnCount() const;
-
- // Count
- //
- // Sets/gets the number of items in the listview. You
- // can set the count to a predetermined value for
- // efficiency.
-
- WBool SetCount( WULong count );
- WULong GetCount( WBool forceCount=FALSE ) const;
-
- // DataAutoHeaders
- //
- // If TRUE, existing header columns are deleted and
- // new columns are added whenever a query is opened.
- // Otherwise columns are left unchanged. Defaults to TRUE.
-
- WBool GetDataAutoHeaders() const;
- WBool SetDataAutoHeaders( WBool set );
-
- // DataColumns
- //
- // DataTarget property
-
- WString GetDataColumns() const;
- WBool SetDataColumns( const WString & cols );
-
- // DataGuardRows
-
- WLong GetDataGuardRows() const;
- WBool SetDataGuardRows( WLong guardRows );
-
- // DataKeptRows
-
- WLong GetDataKeptRows() const;
- WBool SetDataKeptRows( WLong keptRows );
-
- // DataSource
- //
- // DataTarget property
-
- WDataSource *GetDataSource() const;
- WBool SetDataSource( WDataSource *source );
-
- // DataTrackRow
- //
- // DataTarget method
-
- WBool GetDataTrackRow() const;
- WBool SetDataTrackRow( WBool trackRow );
-
- // IconAlignment -- Sets/gets the icon alignment in icon or small
- // icon views. Note that WLVADefault and
- // WLVASnapToGrid are ignored (use the Arrange
- // method instead).
-
- WLVAlignment GetIconAlignment() const;
- WBool SetIconAlignment( WLVAlignment align );
-
- // ImageList
- //
- // Get or set one of the imagelists used by the listview.
- // All imagelists are shared, so it is up to the user
- // to destroy the imagelist after destroying the listview.
-
- WImageList * GetImageList( WLVImageListType type=WLVINormal ) const;
- WBool SetImageList( WImageList * imageList,
- WLVImageListType type=WLVINormal );
-
- // SelectedCount
- //
- // Returns the number of items currently selected
-
- WUInt GetSelectedCount() const;
-
- // ShowHeaders -- If true, headers are shown in report view.
-
- WBool GetShowHeaders() const;
- WBool SetShowHeaders( WBool show );
-
- // TopIndex -- Return the index of the topmost item in list or
- // report view.
-
- WULong GetTopIndex() const;
-
- // View -- Sets/gets the current view. Defaults to WLVTIcon.
- //
-
- WLVViewType GetView() const;
- WBool SetView( WLVViewType view,
- WBool useResizeToAvoidPaintingBug=FALSE );
-
- // VisibleCount -- Calculates the number of items that can fit
- // vertically in the visible area of the control
- // when in list or report/detail view.
-
- WULong GetVisibleCount( WBool includePartiallyVisible=FALSE ) const;
-
- /**********************************************************
- * Methods
- *********************************************************/
-
- // Add
- //
- // Add a new item/row. Items start at 0. If you set
- // item to -1, it will add it at the end. The label can
- // be NULL. The imageIndex refers to the index into the
- // imagelist, set it to -1 for no image. The itemUserData
- // is per-item userdata. You can optionally specify
- // any number of subitems, which are all strings.
- // Returns the new row index, or -1 if error.
-
- #define WLVTextCallback ((WChar *) -1)
- WLong Add( const WChar *label, WLong imageIndex=-1,
- WShort stateImageIndex=0, WLong itemNumber=-1,
- void *itemUserData=NULL, WLong numSubItems=0, ... );
-
- // AddColumn
- //
- // Add a new column. Columns start at 0. If you set
- // it to -1, the column will be added to the end.
- // Specify WCOLUMN_DEFAULT for the default column width,
- // or WCOLUMN_TITLELENGTH to size it according to the length
- // of the header title. You can pass NULL for the title.
- // Returns the new column index, or -1 if error.
-
- #define WCOLUMN_DEFAULT (-1)
- #define WCOLUMN_TITLELENGTH (-2)
-
- WLong AddColumn( const WChar *title, WLong columnNumber=-1,
- WLong width=WCOLUMN_TITLELENGTH,
- WLVColumnAlignment align=WLVCALeft,
- WLong subItemNumber=-1 );
-
- // Arrange
- //
- // Arranges the icons in the listview and optionally sorts
- // them by label.
-
- WBool Arrange( WLVAlignment align=WLVADefault );
-
- // CreateDragImage
- //
- // Returns an imagelist that can be used for drawing purposes
- // during a drag operation. Caller must delete the image
- // list when done.
-
- WImageList CreateDragImage( WULong itemNumber,
- WPoint *initialPosition=NULL ) const;
-
- // DeleteAll
- //
- // Clear all the items in the listview.
-
- WBool DeleteAll();
-
- // DeleteAllColumns
-
- WBool DeleteAllColumns();
-
- // DeleteColumn
- //
- // Delete an individual column.
-
- WBool DeleteColumn( WULong columnNumber );
-
- // Delete
- //
- // Delete an item or group of items (iff last > first).
-
- WBool Delete( WULong first, WULong last=0 );
-
- // EditLabel
- //
- // Invoke label editing for an item.
-
- WWindowHandle EditLabel( WULong itemNumber );
-
- // EnsureIsVisible
- //
- // Ensures that an item is fully/partially visible, scrolling
- // it into view if necessary. Note that EnsureIsVisible
- // works in all modes.
-
- WBool EnsureIsVisible( WULong itemNumber, WBool fullyVisible=TRUE );
-
- // Enumerate
- //
- // Invokes the callback on each item in the list view.
-
- WBool Enumerate( WObject * client, WListViewCallback callback,
- void * userData=NULL );
-
- // Retrieve
- //
- // Retrieve the next/previous item by state or position.
- // If retrieving by state, the startAt value is where the
- // search should start (but excludes the item itself).
- // If retrieving by position, the point indicates the position
- // beneath which to look for the item.
- // Returns the index of the item, or -1 if no item is found/end
- // of search.
-
- WLong Retrieve( WLong startAt=-1, WULong flags=WLVNISelected ) const;
- WLong Retrieve( const WPoint & pt );
-
- // RetrieveMultiple
- //
- // Retrieve multiple next/previous items by state or position.
- // Returns the an array of indices of the items.
-
- WULongArray RetrieveMultiple( WULong flags=WLVNISelected ) const;
-
- // Redraw
- //
- // Force the control to redraw a range of items.
- // The specified items are not actually redrawn until the
- // window receives a paint message. To repaint immediately,
- // call the Update() function after calling this function.
-
- WBool Redraw( WULong from, WULong to, WBool force=FALSE );
-
- // Sort
- //
- // Sort the items.
-
- WBool Sort( WListViewSortCallback sortFunction );
- WBool Sort( WObject * object,
- WListViewSortMemberCallback sortFunction );
-
- /**********************************************************
- * Item Properties
- *********************************************************/
-
- // ColumnAlignment
-
- WLVColumnAlignment GetColumnAlignment( WLong columnNumber ) const;
- WBool SetColumnAlignment( WLong columnNumber,
- WLVColumnAlignment alignment );
-
- // ColumnText
-
- WString GetColumnText( WLong columnNumber ) const;
- WBool SetColumnText( WLong columnNumber, const WString & text );
-
- // ColumnWidth
- //
- // Get or set the width of the given column. Note that in
- // report view, the columns go from 0 to n. You can also use
- // this is list view to get/set the (only) column's width,
- // but you have to use a column number of -1.
-
- #define WCOLUMN_AUTOSIZE_USEITEMS (-1)
- #define WCOLUMN_AUTOSIZE_USETITLE (-2)
-
- WLong GetColumnWidth( WLong columnNumber ) const;
- WBool SetColumnWidth( WLong columnNumber, WLong width );
-
- // ImageIndex -- Sets/Gets the index of the icon in the icon and
- // small icon image lists
-
- WBool SetImageIndex( WULong item, WLong index );
- WLong GetImageIndex( WULong item ) const;
-
- // Position
- //
- // Get/set the position of an item in icon or small icon view.
-
- WBool GetPosition( WLong itemNumber, WPoint & position ) const;
- WBool GetPosition( WLong itemNumber, WLong & x, WLong & y ) const;
- WBool SetPosition( WLong itemNumber, const WPoint & position );
- WBool SetPosition( WLong itemNumber, WLong x, WLong y );
-
- // Rectangle
- //
- // Get/set the rectangle where the control is placed
- // If an itemNumber is supplied, then the rectangle applies
- // to the position
-
- WRect GetRectangle( WLong itemNumber, WLVRectType type=WLVRText );
-
- // State
- //
- // Get/set the state of an item. A mask value is used to
- // determine which states to get/set, by default it's the
- // selected state (but you can get/set multiple states).
-
- WULong GetState( WLong itemNumber,
- WULong mask=WLVSelectedState ) const;
- WBool SetState( WLong itemNumber, WULong state,
- WULong mask=WLVSelectedState );
-
- // StateImageIndex
-
- WBool SetStateImageIndex( WULong itemNumber, WShort index );
- WShort GetStateImageIndex( WULong itemNumber ) const;
-
- // Text
- //
- // Get or set the caption of an item/subitem. If no parm
- // is given, defaults to column 0 which is the item label.
- //
-
- WString GetText( WULong itemNumber, WULong subItemNumber=0 ) const;
- WBool SetText( WULong itemNumber, const WString & text,
- WULong subItemNumber=0, WBool checkOldValue=TRUE );
-
- // UserData
- //
- // Get or set the per-item data.
-
- WBool SetUserData( WULong itemNumber, void *itemUserData );
- void *GetUserData( WULong itemNumber ) const;
-
- /**********************************************************
- * Default Event Handlers
- *********************************************************/
-
- WBool DragEnterHandler( WListView *, WDragEventData * );
- WBool DragOverHandler( WListView *, WDragEventData * );
- WBool DragLeaveHandler( WListView *, WDragEventData * );
-
- WBool DestroyEventHandler( WListView *, WEventData * );
-
- WBool ContextMenuEventHandler( WWindow *,
- WContextMenuEventData * event );
-
- // Event handlers for the DataTarget
-
- WBool DataOpenHandler( WListView *, WDataOpenEventData *ev );
- WBool DataCloseHandler( WListView *, WDataCloseEventData *ev );
- WBool DataAvailableHandler( WListView *, WDataAvailableEventData *ev );
- WBool DataRequestHandler( WListView *, WDataRequestEventData *ev );
- WBool DataGuardRowHandler( WListView *, WDataGuardRowEventData * ev );
-
- /**********************************************************
- * Overrides
- *********************************************************/
-
- virtual WColor GetBackColor( WBool getResultingColor=TRUE ) const;
-
- virtual WBool SetParent( const WWindow * parent );
-
- virtual WBool WantsDragMessage( WULong whichButton ) const;
- virtual WBool FillDragEventData( WDragEventData & event ) const;
-
- virtual WBool Destroy();
-
- virtual WBool ProcessMessage( const WMessage & msg,
- WLong & returns );
-
- virtual WBool SetBackColor( const WColor & col );
-
- virtual WBool SetForeColor( const WColor & col );
-
- virtual WBool CloneWindow( WStyle newStyle, WStyle newExStyle,
- void * data=NULL );
-
- virtual WRect GetRectangle( WBool absolute=FALSE ) const;
-
- virtual WBool SetText( const WString & str );
-
- virtual WString GetText() const;
-
- virtual WBool SetUserData( void * userData );
-
- virtual void * GetUserData() const;
-
- protected:
- virtual WBool ProcessNotify( WUInt id, WNotify code, WNotifyInfo info,
- WLong & returns );
-
- public:
- virtual const WChar * InitializeClass();
-
- virtual WStyle GetDefaultStyle() const;
-
- /**********************************************************
- * Internal
- *********************************************************/
-
- protected:
-
- void UpdateExtents( WLong count );
-
- WBool AddDataRow( WLong row, WLong itemNumber = -1 );
-
- WLong FindDataRow( WLong row, WLong itemCount = -1 );
-
- WBool AllocDTTable();
-
- WBool IndirectUserData( WBool indirect );
-
- void RenumberDataRows();
- WBool HandleRefreshRow( WLong reason, WLong row, WLong count );
-
- WBool SetRealUserData( WULong itemNumber, void *itemUserData );
- void *GetRealUserData( WULong itemNumber ) const;
-
- void doDataTargetScroll();
-
- virtual void EventNotice( WEventID id, WEventNotice type );
-
- /**********************************************************
- * Data Members
- *********************************************************/
-
- protected:
-
- WImageList * _normalImages;
- WImageList * _smallImages;
- WImageList * _stateImages;
- WULong _itemBufferLength;
- WChar * _itemBuffer;
- WULong _columnBufferLength;
- WChar * _columnBuffer;
- WLong _maxColumnNumber;
- WBool _indirectUserData;
- WDataTargetTable * _dataTarget;
- WBool _dataFilling;
- WBool _wasPainting;
- WBool _ignoreDataAvailableMove;
- WBool _ignoreItemChanged;
- WLong _dragSelected;
- WLong _addRow;
- WBool _labelBeingEditted;
- WLong _lastScrollPos;
- WLong _scrollUp;
- WLong _scrollDown;
- WBool _scrolling;
- WDWord _lvEventBits;
- WBool _autoHeaders;
- WULong _count;
- };
-
- #ifndef _WTEMPLAT_HPP_INCLUDED
- # include "wtemplat.hpp"
- #endif
-
- #ifndef _WNO_PRAGMA_PUSH
- #pragma enum pop;
- #pragma pack(pop);
- #endif
-
- #endif // _WLISTVW_HPP_INCLUDED
-